From 348c7389957364903852d6826a4d5b93ed2c8454 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 8 Jun 2015 10:58:15 -0700 Subject: [PATCH] Clone less with an extra `Registry` impl --- src/cargo/core/registry.rs | 7 +++++++ src/cargo/sources/path.rs | 7 ++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/cargo/core/registry.rs b/src/cargo/core/registry.rs index 4bd13c29e..c9a65f62d 100644 --- a/src/cargo/core/registry.rs +++ b/src/cargo/core/registry.rs @@ -19,6 +19,13 @@ impl Registry for Vec { } } +impl Registry for Vec { + fn query(&mut self, dep: &Dependency) -> CargoResult> { + Ok(self.iter().filter(|pkg| dep.matches(pkg.summary())) + .map(|pkg| pkg.summary().clone()).collect()) + } +} + /// This structure represents a registry of known packages. It internally /// contains a number of `Box` instances which are used to load a /// `Package` from. diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index a3f058573..80f919542 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -59,7 +59,7 @@ impl<'cfg> PathSource<'cfg> { } } - pub fn read_packages(&self) -> CargoResult> { + fn read_packages(&self) -> CargoResult> { if self.updated { Ok(self.packages.clone()) } else if self.id.is_path() && self.id.precise().is_some() { @@ -272,10 +272,7 @@ impl<'cfg> Debug for PathSource<'cfg> { impl<'cfg> Registry for PathSource<'cfg> { fn query(&mut self, dep: &Dependency) -> CargoResult> { - let mut summaries: Vec = self.packages.iter() - .map(|p| p.summary().clone()) - .collect(); - summaries.query(dep) + self.packages.query(dep) } } -- 2.30.2